package com.zz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zz.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
//import org.springframework.data.repository.query.Param;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author HUAWEI
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT name FROM role WHERE id IN (SELECT role_id FROM user_role WHERE user_id=(SELECT id FROM user WHERE name=#{principal}))")
    List<String> getUserRoleInfoMapper(@Param("principal") String principal);

    @Select({
            "<script>",
            "select path FROM permission WHERE id IN ",
            "(SELECT permission_id FROM role_permission WHERE role_id IN (",
            "SELECT id FROM role WHERE name IN ",
            "<foreach collection='roles' item='name' open='(' separator=',' close=')'>",
            "#{name}",
            "</foreach>",
            "))",
            "</script>"
    })
    List<String> getUserPermissionInfo(@Param("roles") List<String> roles);

}
